﻿#ifndef TCPDATAPREPROCESSOR_H
#define TCPDATAPREPROCESSOR_H

#include <qobject.h>

class TcpDataPreprocessor : public QObject
{
  Q_OBJECT
private:
  enum PrivateSignalClass
  {
    PrivateSignal
  };
private://static const
  static const QByteArray fakeFlag;
  static const QByteArray trueFlag;
  static const QByteArray beginFlag;
  static const int headLen;
private://property
  QByteArray dataBuffer;//缓存从TcpIOer收到的数据
  int dataLen=0;//解析头部得到的数据体的长度
  char lastChar=0;//用于判断新的头部
private://dependency
public:
  TcpDataPreprocessor();
  virtual ~TcpDataPreprocessor();
signals:
  void signal_decoded(QByteArray data,TcpDataPreprocessor::PrivateSignalClass=TcpDataPreprocessor::PrivateSignal);
public:
  QByteArray* code(QByteArray* data);
  void decode(QByteArray data);
private:
  void decode1();
  void decodeHead();
  void decodeBody();
  void init();
private:
  QByteArray* addFakeFlag(QByteArray *data);
  QByteArray* removeFakeFlag(QByteArray *data);
  QByteArray* addHead(QByteArray *data);
public://geter and seter
};
#endif // TCPDATAPREPROCESSOR_H
